package com.sunlands.qdcy.deskmate.util;

import org.apache.commons.lang3.time.DateFormatUtils;

import java.math.BigDecimal;
import java.util.UUID;

/**
 * @author zl
 * @version 1.0
 * @date Created in 2020/4/10
 */

public class OrderSnUtil {

    private static final String datepattern = "yyyyMMddHHmmssSSS";


    /**
     * 1位支付方式 + 17位时间 + 10位uuid哈希
     * @param payType
     * @return
     */
    public static String getOrderSn(int payType){
        StringBuilder stringBuilder = new StringBuilder(28);
        stringBuilder.append(payType)
                .append(DateFormatUtils.format(System.currentTimeMillis(),datepattern));
        int code = UUID.randomUUID().toString().hashCode();
        if (code < 0) {
            code = -code;
        }
        stringBuilder.append(String.format("%010d", code));
        return stringBuilder.toString();
    }


    public static void main(String[] args) {

        long n = 1000000L;
        long begin = System.currentTimeMillis();
        for(int i=0;i<n;i++){
            getOrderSn(1);
        }
        BigDecimal cost = BigDecimal.valueOf(System.currentTimeMillis()- begin).divide(BigDecimal.valueOf(n),10, BigDecimal.ROUND_HALF_EVEN);
        System.out.println(cost.doubleValue());

    }






}
